class Solution {//leetcode525——连续数组
public:
    int findMaxLength(vector<int>& nums) {
        int n=nums.size(),sum=0,ret=0;
        unordered_map<int,int> hash;
        hash[0]=-1;
        
        for(int i=0;i<n;i++){
            if(nums[i]==0) sum+=-1;
            else sum+=1;
            
            if(hash.count(sum)) {
                ret=max(ret,i-hash[sum]);
            }
            else hash[sum]=i;
        }
        return ret;
    }
};